package com.owen.utils;

import cn.hutool.core.io.resource.ResourceUtil;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.List;

/**
 * 读取resources的文本文件
 */
public class ReadFileUtil {

    /**
     *
     * @param fileName 文件名
     * @return 文件内容
     */
    public static List<String> read(String fileName) {
        List<String> context = new ArrayList<>();
        InputStream stream = ResourceUtil.getStream(fileName);
        InputStreamReader is = new InputStreamReader(stream, StandardCharsets.UTF_8);
        BufferedReader b = new BufferedReader(is);
        String line = null;
        try {
            while ((line = b.readLine()) != null) {
                context.add(line);
            }
        }catch (IOException e) {
            e.printStackTrace();
        }
        return context;
    }

}
